package com.niannian.activity;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.xmlpull.v1.XmlPullParser;

import android.app.Activity;
import android.app.TabActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.Transformation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;
import com.niannian.db.MyDBUser;
import com.niannian.dialog.YesNoDialog2;
import com.niannian.dialog.YesNoDialog2.onSimpleOnCancelListener;
import com.niannian.dialog.YesNoDialog2.onSimpleOnClicklListener;
import com.niannian.photo.AlbumActivity;
import com.niannian.service.MessageService;
import com.niannian.util.Common;
import com.niannian.util.MessageRecieveManager;
import com.niannian.util.PlayerManager;
import com.niannian.util.RecordManager;
import com.niannian.util.Sys;
import com.niannian.util.UmengPage;
import com.niannian.util.UserInfoManager;
import com.niannian.util.VAR;
import com.niannian.util.Version;
import com.niannian.MyApplication;
import com.niannian.R;
import com.umeng.analytics.MobclickAgent;

/**
 * 
 * 主界面类
 * 
 * @author shengl
 * 
 */
@SuppressWarnings("deprecation")
public class HomeActivity extends TabActivity {

	public static final String NEWS_TAB = "动态";
	public static final String NEWSS_TAB = "咚咚";
	public static final String MY_TAB = "我的";
	private TabHost tabHost;
	Map<String, LinearLayout> indicators = new HashMap<String, LinearLayout>();
	private NotificationReceiver notificationReceiver;

	public static Activity activity;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		activity = this;
		MyDBUser userInfoManager = UserInfoManager.getUserInfoInstance();
		// JPushInterface.resumePush(this);
		JPushInterface.setAliasAndTags(HomeActivity.this, userInfoManager.id + "", null, new TagAliasCallback() {
			@Override
			public void gotResult(int code, String alias, Set<String> tags) {
				Log.d("code", "[TagAliasCallback], code: " + code);
				Log.d("alias", "[TagAliasCallback], code: " + alias);
				Log.d("tags", "[TagAliasCallback], code: " + tags);
			}
		});

		tabHost = this.getTabHost();
		TabSpec classSpec = tabHost.newTabSpec(NEWS_TAB).setContent(new Intent(this, FamilyNewsActivity.class));
		TabSpec newssSpec = tabHost.newTabSpec(NEWSS_TAB).setContent(new Intent(this, NewssActivity.class));
		TabSpec mySpec = tabHost.newTabSpec(MY_TAB).setContent(new Intent(this, MyActivity.class));

		classSpec.setIndicator(proIndicators(NEWS_TAB));
		newssSpec.setIndicator(proIndicators(NEWSS_TAB));
		mySpec.setIndicator(proIndicators(MY_TAB));
		tabHost.addTab(classSpec);
		tabHost.addTab(newssSpec);
		tabHost.addTab(mySpec);
		tabHost.setCurrentTab(1);
		tabHost.setCurrentTab(0);
		tabHost.setOnTabChangedListener(new OnTabChangeListener() {
			@Override
			public void onTabChanged(String tabId) {
				setSelected(tabId);
				showAddView(tabId);
			}
		});

		recording();
		MianAdd();
		registerMessageReceiver();
		checkMsg(NEWS_TAB);
		checkMsg(NEWSS_TAB);
		checkMsg(MY_TAB);
		// 开启轮旋拉取系统
		Intent intent = new Intent(HomeActivity.this, MessageService.class);
		startService(intent);
		upVersion();// 查询新版本
		weixfirst();// 是否微信第一次登录

	}

	private void setSelected(String type) {
		for (String key : indicators.keySet()) {
			// ((ImageView)
			// (indicators.get(key).getChildAt(0))).setSelected(key.equals(type));
			((TextView) (indicators.get(key).getChildAt(0))).setSelected(key.equals(type));
		}
	}

	private LinearLayout proIndicators(String tabName) {
		LinearLayout content = new LinearLayout(this);
		content.setGravity(Gravity.CENTER);
		content.setOrientation(LinearLayout.HORIZONTAL);
		// int Padding = Sys.Dp2Px(this, 40);
		int res;
		if (NEWS_TAB.equals(tabName)) {
			res = R.drawable.tab_family_news;
			// content.setPadding(0, 0, Padding, 0);
		} else if (NEWSS_TAB.equals(tabName)) {
			res = R.drawable.tab_news;
			// Padding = Sys.Dp2Px(this, 40 + 15);
			// content.setPadding(Padding, 0, 0, 0);
		} else {
			res = R.drawable.tab_my;
		}
		/*
		 * Drawable viewTop = getResources().getDrawable(res); ImageView ivt =
		 * new ImageView(this); ivt.setImageDrawable(viewTop);
		 * LinearLayout.LayoutParams lp = new
		 * LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
		 * LinearLayout.LayoutParams.WRAP_CONTENT); content.addView(ivt, 0, lp);
		 * indicators.put(tabName, content);
		 */
		TextView tab = new TextView(this);
		tab.setText(tabName);
		Drawable viewTop = getResources().getDrawable(res);
		int width = Sys.Dp2Px(this, 32);
		viewTop.setBounds(0, 0, width, width);

		int textSize = Sys.Dp2Px(this, 15);
		tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
		// tab.setDuplicateParentStateEnabled(true);
		tab.setCompoundDrawables(null, viewTop, null, null);
		// tab.setTextColor(Color.parseColor("#666666"));
		// tab.setTextColor(this.getResources().getColor(R.drawable.tab_txt));

		try {
			XmlPullParser xrp = getResources().getXml(R.drawable.tab_txt);
			ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
			tab.setTextColor(csl);
		} catch (Exception e) {
		}

		tab.setGravity(Gravity.CENTER);
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
		content.addView(tab, 0, lp);
		indicators.put(tabName, content);

		return content;
	}

	public void setRedIcon(String type, String content, boolean show, int p) {
		LinearLayout parent = indicators.get(type);
		TextView curRed = (TextView) parent.getChildAt(1);
		if (curRed == null) {
			curRed = new TextView(this);
			curRed.setTextColor(getResources().getColor(R.color.white));
			curRed.setGravity(Gravity.CENTER);
			// curRed.setBackgroundResource(R.drawable.red_point);
			curRed.setBackgroundResource(R.drawable.msg_p);

			curRed.setText(content + "");
			curRed.setTextSize(12);
			// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(12,
			// 12);
			// lp.gravity = Gravity.TOP;
			// lp.topMargin = 10;
			int h = Sys.Dp2Px(this, 15);
			LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(h, h);
			lp.gravity = Gravity.TOP;
			lp.topMargin = 10;
			lp.leftMargin = -6;

			parent.addView(curRed, 1, lp);
		} else {
			curRed.setText(content);
		}
		int h = 0;
		if (p == 1) {
			h = Sys.Dp2Px(this, 20);
		} else {
			h = Sys.Dp2Px(this, 10);
		}
		LayoutParams params = curRed.getLayoutParams();
		params.height = h;
		params.width = h;
		curRed.setLayoutParams(params);
		if (show) {
			curRed.setVisibility(View.VISIBLE);

		} else {
			curRed.setVisibility(View.INVISIBLE);
		}
	}

	public void checkMsg(String type) {
		int msgCount = 0;
		if (NEWS_TAB.equals(type)) {
			int familyNewsNum = MessageRecieveManager.FAMILY_NEWS_UPDATE_NUM;
			int NewsNum = MessageRecieveManager.NEWS_UPDATE__NUM;

			if (NewsNum > 0) {
				if (NewsNum > 99) {
					NewsNum = 99;
				}
				setRedIcon(type, NewsNum + "", true, 1);
			} else {
				if (familyNewsNum > 0) {
					setRedIcon(type, "", true, 2);
				} else {
					setRedIcon(type, "", false, 2);
				}
			}

		} else if (NEWSS_TAB.equals(type)) {
			msgCount = MessageRecieveManager.total_count;
			if (msgCount > 0) {
				if (msgCount > 99) {
					msgCount = 99;
				}
				setRedIcon(type, msgCount + "", true, 1);
			} else {
				setRedIcon(type, "", false, 2);
			}
		}

	}

	public class NotificationReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (MessageRecieveManager.FAMILY_NEWS_UPDATE_ACTION.equals(action)) {
				checkMsg(NEWS_TAB);
			}
			if (MessageRecieveManager.GREETING_NEWS_UPDATE_ACTION.equals(action)) {
				checkMsg(NEWSS_TAB);
			}

			if (MessageRecieveManager.NEWS_UPDATE_ACTION.equals(action)) {
				checkMsg(NEWS_TAB);
			}

			if (MessageRecieveManager.FAMILY_NEWS_ADD_ACTION.equals(action)) {
				// tabHost.setCurrentTab(0);
				// rl_recording.setVisibility(View.GONE);
				// btn_recording.setVisibility(View.VISIBLE);
				// btn_delete.setVisibility(View.GONE);
			}
			if (MessageRecieveManager.GREETING_ADD_ACTION.equals(action)) {
				// rl_recording.setVisibility(View.GONE);
				// btn_recording.setVisibility(View.VISIBLE);
				// btn_delete.setVisibility(View.GONE);
			}
			if (MessageRecieveManager.NEWSS_TOTAL_COUNT_ACTION.equals(action)) {
				checkMsg(NEWSS_TAB);
			}
		}
	}

	public void registerMessageReceiver() {
		notificationReceiver = new NotificationReceiver();
		IntentFilter filter = new IntentFilter();
		filter.setPriority(MessageRecieveManager.MESSAGE_RECEIVED_PRIORITY_MAIN);
		filter.addAction(MessageRecieveManager.FAMILY_NEWS_UPDATE_ACTION);
		filter.addAction(MessageRecieveManager.GREETING_NEWS_UPDATE_ACTION);
		filter.addAction(MessageRecieveManager.FAMILY_NEWS_ADD_ACTION);
		filter.addAction(MessageRecieveManager.GREETING_ADD_ACTION);
		filter.addAction(MessageRecieveManager.NEWS_UPDATE_ACTION);
		filter.addAction(MessageRecieveManager.NEWSS_TOTAL_COUNT_ACTION);

		HomeActivity.this.registerReceiver(notificationReceiver, filter);
	}

	@Override
	protected void onDestroy() {
		unregisterReceiver(notificationReceiver);
		// PollingUtil.stopPollingService(mActivity, NotificationService.class,
		// NOTIFICATION_SERVICE);
		super.onDestroy();
	}

	// 录音
	public static Button btn_recording, btn_delete;

	public static RelativeLayout rl_recording;
	TextView tv_recording_title;
	ImageView iv_volume_show;
	ImageView iv_recording_left_tip;
	ImageView iv_recording_right_tip;

	Button btn_push__fam_news;

	Button btn_push_regards;
	TextView tv_record_tip;

	RecordManager rm;
	String savePath = "";// 语音路径
	Boolean isRecord = false;

	private void recording() {
		btn_recording = (Button) findViewById(R.id.btn_recording);
		btn_recording.setVisibility(View.GONE);
		btn_delete = (Button) findViewById(R.id.btn_delete);
		btn_delete.setVisibility(View.GONE);
		rl_recording = (RelativeLayout) findViewById(R.id.rl_recording);
		rl_recording.setVisibility(View.GONE);
		tv_recording_title = (TextView) findViewById(R.id.tv_recording_title);
		iv_volume_show = (ImageView) findViewById(R.id.iv_volume_show);
		iv_recording_left_tip = (ImageView) findViewById(R.id.iv_recording_left_tip);
		iv_recording_right_tip = (ImageView) findViewById(R.id.iv_recording_right_tip);

		btn_push__fam_news = (Button) findViewById(R.id.btn_push__fam_news);

		btn_push_regards = (Button) findViewById(R.id.btn_push_regards);
		tv_record_tip = (TextView) findViewById(R.id.tv_record_tip);

		if (timeHandler == null) {
			listenerTime();
		}
		rm = new RecordManager(iv_volume_show);
		rm.listenerTime(timeHandler);

		btn_recording.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN && !isRecord) {

					if (System.currentTimeMillis() - VAR.ExitTime > VAR.rINTERVAL) {
						btn_recording.setBackgroundResource(R.drawable.recording_pre);
						startRecord();
						VAR.ExitTime = System.currentTimeMillis();
						isRecord = true;
						rm.setIsRStatus(true);
					}
				} else if (event.getAction() == MotionEvent.ACTION_UP && isRecord) {
					VAR.ExitTime = System.currentTimeMillis();
					btn_recording.setBackgroundResource(R.drawable.recording);
					rm.setIsRStatus(false);
					if (timeCount > 0) {
						MobclickAgent.onEvent(HomeActivity.this, UmengPage.MAKE_AUD_PRESSON);
						endRecord();
					} else {
						rl_recording.setVisibility(View.GONE);
					}
					isRecord = false;
					tv_recording_title.setText("录音");
				}
				return true;
			}
		});

		btn_push__fam_news.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Bundle pBundle = new Bundle();
				pBundle.putString("audPath", savePath);
				pBundle.putInt("aud_len", timeCount);
				pBundle.putInt("sendType", 0);

				Intent intent = new Intent(HomeActivity.this, PushRegardsActivity.class);
				intent.putExtras(pBundle);
				startActivity(intent);
				overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			}
		});
		btn_push_regards.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				Bundle pBundle = new Bundle();
				pBundle.putString("audPath", savePath);
				pBundle.putInt("aud_len", timeCount);
				pBundle.putInt("sendType", 1);

				Intent intent = new Intent(HomeActivity.this, PushRegardsActivity.class);
				intent.putExtras(pBundle);
				startActivity(intent);
				overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			}
		});
		rl_recording.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub

			}
		});

		btn_delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				rl_recording.setVisibility(View.GONE);
				btn_recording.setVisibility(View.VISIBLE);
				btn_delete.setVisibility(View.GONE);
			}
		});

	}

	private void startRecord() {
		PlayerManager.getAudioPlayer(this).playerPause();
		RecordView();
		timeCount = 0;
		tv_record_tip.setText("按住录音");
		tv_recording_title.setText("正在录音...");
		savePath = MyApplication.FILE_PATH_TEMP + ((new Date()).getTime() / 1000) + ".amr";
		File file = new File(savePath);
		rm.setSavePath(file);
		rm.startRecord();
	}

	private void RecordView() {
		btn_delete.setVisibility(View.GONE);
		rl_recording.setVisibility(View.VISIBLE);
		iv_volume_show.setVisibility(View.VISIBLE);
		iv_recording_left_tip.setVisibility(View.VISIBLE);
		iv_recording_right_tip.setVisibility(View.VISIBLE);
		tv_record_tip.setVisibility(View.VISIBLE);
		tv_record_tip.setText("0秒");

		btn_push__fam_news.setVisibility(View.GONE);
		btn_push_regards.setVisibility(View.GONE);
	}

	private void endRecord() {
		btn_recording.setVisibility(View.GONE);
		btn_delete.setVisibility(View.VISIBLE);
		rl_recording.setVisibility(View.VISIBLE);
		iv_volume_show.setVisibility(View.GONE);
		iv_recording_left_tip.setVisibility(View.GONE);
		iv_recording_right_tip.setVisibility(View.GONE);
		tv_record_tip.setVisibility(View.GONE);
		tv_record_tip.setText("0秒");

		btn_push__fam_news.setVisibility(View.VISIBLE);
		Animation animation = new TranslateAnimation(-200, 0, 0, 0);
		animation.setDuration(500);
		btn_push__fam_news.setAnimation(animation);

		btn_push_regards.setVisibility(View.VISIBLE);
		Animation animation2 = new TranslateAnimation(200, 0, 0, 0);
		animation2.setDuration(500);
		btn_push_regards.setAnimation(animation2);
	}

	Handler timeHandler;
	private int timeCount = 0;
	private int MaxTime = 90;
	private int showTime = 30;

	private void listenerTime() {
		timeHandler = new Handler() {
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case 1:
					timeCount++;
					if ((MaxTime - timeCount) < showTime) {

						tv_record_tip.setText(Common.showAudLen(timeCount) + "\n(还能说" + (MaxTime - timeCount) + "秒)");
					} else {
						tv_record_tip.setText(Common.showAudLen(timeCount));
					}

					if (timeCount >= MaxTime) {
						rm.stopRecord();
						endRecord();
					}
					break;
				}
				super.handleMessage(msg);
			}
		};
	}

	//
	private SharedPreferences sp;

	ImageView iv_main_add_bg, iv_main_add_pic, iv_main_add_text, iv_main_add_record, iv_mian_add;
	RelativeLayout rl_mian_add;

	private void MianAdd() {
		iv_main_add_bg = (ImageView) findViewById(R.id.iv_main_add_bg);
		rl_mian_add = (RelativeLayout) findViewById(R.id.rl_mian_add);

		iv_main_add_pic = (ImageView) findViewById(R.id.iv_main_add_pic);
		iv_main_add_text = (ImageView) findViewById(R.id.iv_main_add_text);
		iv_main_add_record = (ImageView) findViewById(R.id.iv_main_add_record);
		iv_mian_add = (ImageView) findViewById(R.id.iv_mian_add);

		iv_mian_add.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				if (iv_main_add_pic.getVisibility() == View.VISIBLE) {
					hledView();
				} else {
					iv_main_add_pic.setVisibility(View.VISIBLE);
					iv_main_add_text.setVisibility(View.VISIBLE);
					iv_main_add_record.setVisibility(View.VISIBLE);
					iv_main_add_bg.setVisibility(View.VISIBLE);
					int w = iv_mian_add.getWidth();

					Animation animationpic = new TranslateAnimation(0, -2 * w, 0, 0);
					animationpic.setDuration(300);
					animationpic.setFillAfter(true);
					iv_main_add_pic.setAnimation(animationpic);

					Animation animationtext = new TranslateAnimation(0, 0, 0, -2 * w);
					animationtext.setDuration(300);
					animationtext.setFillAfter(true);
					iv_main_add_text.setAnimation(animationtext);

					int rw = (int) (1.5 * w);
					Animation animationrecord = new TranslateAnimation(0, -rw, 0, -rw);
					animationrecord.setDuration(300);
					animationrecord.setFillAfter(true);
					iv_main_add_record.setAnimation(animationrecord);

					// iv_mian_add.setImageResource(R.drawable.main_add_c);

					RotateAnimation animation = new RotateAnimation(0f, 135f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
					animation.setDuration(300);
					animation.setFillAfter(true);
					iv_mian_add.startAnimation(animation);
				}
			}
		});
		iv_main_add_pic.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				hledView();
				startActivity(new Intent(HomeActivity.this, PushRegardsActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_PIC));

			}
		});
		iv_main_add_text.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				hledView();
				startActivity(new Intent(HomeActivity.this, PushRegardsActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_TEXT));

			}
		});
		iv_main_add_record.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				hledView();
				startActivity(new Intent(HomeActivity.this, PushRegardsActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_RECORD));

			}
		});

		iv_main_add_bg.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View arg0, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) {

					float x = event.getX();
					float y = event.getY();
					if (containPoint(iv_main_add_pic, x, y)) {
						hledView2();
						startActivity(new Intent(HomeActivity.this, AlbumActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_PIC));
						MobclickAgent.onEvent(activity, UmengPage.pic_post_add);
						return true;
					} else if (containPoint(iv_main_add_text, x, y)) {
						hledView2();
						startActivity(new Intent(HomeActivity.this, PushRegardsActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_TEXT));
						MobclickAgent.onEvent(activity, UmengPage.text_post_add);
						return true;
					} else if (containPoint(iv_main_add_record, x, y)) {
						hledView2();
						startActivity(new Intent(HomeActivity.this, RecordActivity.class).putExtra("from", PushRegardsActivity.FROM_MIAN_RECORD));
						MobclickAgent.onEvent(activity, UmengPage.aud_post_add);
						return true;
					} else {
						hledView2();
					}

				}
				return true;
			}
		});

	}

	private boolean containPoint(View view, float x, float y) {
		Transformation trans = new Transformation();
		Animation anim = view.getAnimation();
		anim.getTransformation(view.getDrawingTime(), trans);
		Matrix matrix = trans.getMatrix();

		int dx = view.getLeft();
		int dy = view.getTop();

		x -= dx;
		y -= dy;

		// Invert Matrix
		Matrix mat = new Matrix();
		if (matrix.invert(mat)) {
			float[] pointsSrc = new float[] { x, y };
			float[] pointsEnd = new float[] { 0, 0 };

			// Get the point in inverted matrix.
			mat.mapPoints(pointsEnd, pointsSrc);

			// Offset the point because we translate matrix which dx and dy
			// before.
			x = pointsEnd[0] + dx;
			y = pointsEnd[1] + dy;
		}

		Rect rect = new Rect();
		view.getHitRect(rect);
		return rect.contains((int) x, (int) y);
	}

	private void showAddView(String tabId) {

		if (NEWS_TAB.equals(tabId)) {
			rl_mian_add.setVisibility(View.VISIBLE);
			if (iv_main_add_pic.getVisibility() == View.VISIBLE) {
				iv_main_add_bg.setVisibility(View.VISIBLE);
			} else {
				iv_main_add_bg.setVisibility(View.GONE);
			}
		} else {
			rl_mian_add.setVisibility(View.GONE);
			iv_main_add_bg.setVisibility(View.GONE);
		}
	}

	private void hledView() {

		iv_main_add_pic.setVisibility(View.GONE);
		iv_main_add_text.setVisibility(View.GONE);
		iv_main_add_record.setVisibility(View.GONE);

		iv_main_add_bg.setVisibility(View.GONE);

		int w = iv_mian_add.getWidth();

		Animation animationpic = new TranslateAnimation(-2 * w, 0, 0, 0);
		animationpic.setDuration(300);
		animationpic.setFillAfter(false);
		iv_main_add_pic.setAnimation(animationpic);

		Animation animationtext = new TranslateAnimation(0, 0, -2 * w, 0);
		animationtext.setDuration(300);
		animationtext.setFillAfter(false);
		iv_main_add_text.setAnimation(animationtext);

		int rw = (int) (1.4 * w);
		Animation animationrecord = new TranslateAnimation(-rw, 0, -rw, 0);
		animationrecord.setDuration(300);
		animationrecord.setFillAfter(false);
		iv_main_add_record.setAnimation(animationrecord);

		RotateAnimation animation = new RotateAnimation(135f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		animation.setDuration(300);
		animation.setFillAfter(true);
		iv_mian_add.startAnimation(animation);

	}

	private void hledView2() {

		iv_main_add_pic.setVisibility(View.GONE);
		iv_main_add_text.setVisibility(View.GONE);
		iv_main_add_record.setVisibility(View.GONE);

		iv_main_add_bg.setVisibility(View.GONE);

		int w = iv_mian_add.getWidth();

		Animation animationpic = new TranslateAnimation(-2 * w, 0, 0, 0);
		animationpic.setDuration(10);
		animationpic.setFillAfter(false);
		iv_main_add_pic.setAnimation(animationpic);

		Animation animationtext = new TranslateAnimation(0, 0, -2 * w, 0);
		animationtext.setDuration(10);
		animationtext.setFillAfter(false);
		iv_main_add_text.setAnimation(animationtext);

		int rw = (int) (1.4 * w);
		Animation animationrecord = new TranslateAnimation(-rw, 0, -rw, 0);
		animationrecord.setDuration(10);
		animationrecord.setFillAfter(false);
		iv_main_add_record.setAnimation(animationrecord);

		RotateAnimation animation = new RotateAnimation(135f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		animation.setDuration(10);
		animation.setFillAfter(true);
		iv_mian_add.startAnimation(animation);

	}

	private void upVersion() {
		Version version = new Version(HomeActivity.this, true, false) {

			@Override
			public void showLatestVersion(String latestVersion, String desc, String downloadurl, String datetime) {

			}

			@Override
			public void showVersionState(int versionState) {
			}
		};
		version.init(null).execute();

	}

	private void weixfirst() {
		SharedPreferences sp = getSharedPreferences("userinfo", Context.MODE_PRIVATE);
		if (sp.getBoolean("weixfirst", false)) {
			if (UserInfoManager.getUserInfoInstance().login_count <= 1) {
				initDialog();
			}
		}
	}

	YesNoDialog2 tip;

	private void initDialog() {
		tip = new YesNoDialog2(HomeActivity.this, "为了账号安全考虑, 我们建议您绑定手机号. 绑定后, 您可以用手机号直接登录, 或者找回密码.");
		tip.setcancelButtonText("以后再说");
		tip.setConfimButtonText("开始绑定");
		tip.setOnCancelListener(new onSimpleOnCancelListener() {

			@Override
			public void onCancel() {
				tip.dismiss();
			}
		});
		tip.setOnConfimClickListener(new onSimpleOnClicklListener() {

			@Override
			public void onClick() {
				startActivity(new Intent(HomeActivity.this, BindingPhoneActivity.class));
				tip.dismiss();
			}
		});
		tip.show();
	}
}